import { defineStore } from 'pinia'
import { ref } from 'vue'

// 定义 Store
export const useOfflineStore = defineStore(
  'offlinedata',
  () => {
    // xlsx文件导入后所获取的原始数据
    const records = ref([])
    //采集完后的xlsx数据
    // const xlsx = ref({})
    // 设置records数据
    const setRecords = (value) => {
      // console.log(value)
      records.value = value
    }
    // 清空records 数据
    const clearRecords = () => {
      records.value = []
    }
    // const setXlsx = (value) => {
    //   xlsx.value = value
    // }

    // const clearXlsx = () => {
    //   records.value = {}
    // }

    // 记得 return
    return {
      records,
      // xlsx,
      // setXlsx,
      // clearXlsx,
      setRecords,
      clearRecords,
    }
  },
  {
    // 网页端配置
    // persist: true,
    // 小程序端配置
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          return uni.setStorageSync(key, value)
        },
      },
    },
  },
)
